//---------------------------------------------------------------------------

#ifndef h_designcontrolH
#define h_designcontrolH
//---------------------------------------------------------------------------
class TMainForm;
class HStage;
class h_xml::HXmlTree;

class HDesignControl : public TScrollingWinControl
{
public :

        typedef TScrollingWinControl inherited;
        friend TMainForm;
        __fastcall virtual HDesignControl(Classes::TComponent* AOwner);
        __fastcall virtual ~HDesignControl(void);
        bool __fastcall GroupExist(const UTF8String &Name);
        void __fastcall SaveToJobList(map<UTF8String, HJobListInfo> &JobMap,
           bool CriticalFlag);
        void __fastcall SaveToPartTimeList(vector<HPartTimeInfo> &PartVec);
        void __fastcall SaveToGanttList(const TDateTime &StartTime,
           const TDateTime &EndTime, bool PartitionFlag, int Time, vector<HGanttInfo> &Vec);
        HStage * __fastcall FindControlByName(const UTF8String &Name);
        void __fastcall SetFocusedJob(const UTF8String &Name,
           bool ScrollToCenter = false);
        void __fastcall ReloadUpperGroupMap(const UTF8String &Name,
           map<UTF8String, UTF8String> &UpperGroupMap);
        void __fastcall RefreshBatchColor(int ServerIdx);

private :

        static const int GridInterval = 8;
        TControlCanvas *Canvas;

        struct HLinkInfo
        {
           UTF8String Name;
           UTF8String StartControl;
           UTF8String EndControl;
        };

        map<UTF8String, HStage*> ControlMap;
        map<UTF8String, HLinkInfo> LinkMap;
        UTF8String FocusedJobName;

        void __fastcall WMPaint(TWMPaint &Message);
        void __fastcall WMLButtonDown(TWMLButtonDown &Message);
        void __fastcall WMLButtonDblClk(TWMLButtonDblClk &Message);
        void __fastcall WMRButtonUp(TWMRButtonUp &Message);

        void __fastcall DrawLink(const UTF8String &Name, bool First);
        void __fastcall GetLinkPoints(const UTF8String &Name,
           vector<TPoint> &Points, int &Type);
        UTF8String __fastcall FindControlByPos(int x, int y);
        UTF8String __fastcall NewLinkName(void);
        bool __fastcall LinkExist(const UTF8String &Name);
        void __fastcall LoadFromXmlTree(const UTF8String &GroupId,
           HXmlTree *XmlTree, bool XmlPropertyFlag);
        void __fastcall RefreshFromXmlTree(HXmlTree *XmlTree,
           bool XmlPropertyFlag, UTF8String &ErrorJobName);
        void __fastcall RefreshCaption();

protected :

        void __fastcall WndProc(TMessage &Message);
        BEGIN_MESSAGE_MAP
           VCL_MESSAGE_HANDLER(WM_PAINT, TWMPaint,
              WMPaint);
           VCL_MESSAGE_HANDLER(WM_LBUTTONDOWN, TWMLButtonDown, WMLButtonDown);
           VCL_MESSAGE_HANDLER(WM_LBUTTONDBLCLK, TWMLButtonDblClk,
              WMLButtonDblClk);
           VCL_MESSAGE_HANDLER(WM_RBUTTONUP, TWMRButtonUp,
              WMRButtonUp);
        END_MESSAGE_MAP(TScrollingWinControl);
};
#endif
